<template>
	<view class="index" v-if="token">
		<!-- 背景 -->
		<navBar class="navBar" backColor="#fff" background="transparent" isBack></navBar>
		<view class="i_bg"><image :src="`${baseImg}/static/my/bg_1.png`"></image></view>

		<!-- 内容 -->
		<view class="i_contain">
			<view class="i_cTit">{{type=='superHK'?'电脑端超级管家后台':'电脑端管理后台'}}</view>
			<view class="i_cItem">
				<view class="i_cLabel">登录地址：</view>
				<view class="i_cCan">
					<view class="i_cCopy" @click="copyContent(html)">复制</view>
					<view class="i_cCont omit-1">{{ html }}</view>
				</view>
			</view>
			<view class="i_cItem">
				<view class="i_cLabel">登录账号：</view>
				<view class="i_cCan">
					<view class="i_cCopy" @click="copyContent(userAccount)">复制</view>
					<view class="i_cCont omit-1">{{ userAccount }}</view>
				</view>
			</view>
			<view class="i_cItem">
				<view class="i_cLabel">初始密码：</view>
				<view class="i_cCan">
					<view class="i_cCopy" @click="copyContent(userPassword)">复制</view>
					<view class="i_cCont omit-1">{{ userPassword }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import service_enter from '@/service/enter.js';
import { GetSuperAccount } from '@/service/superHK.js';

export default {
	data() {
		return {
			baseImg: this.$static,
			loading: true,
			userMobile: null,
			userAccount: null,
			userPassword: null,
			token: '',
			role: '',
			type:'',
			html: 'https://manager.ryz1620.com'
		};
	},

	onLoad(options) {
		this.type = options.type, //shuperHk-超级管家
		this.userMobile = this.$store.state.index.userMobile;
		let token = this.$store.state.index.token;
		this.token = token;
		let role = this.$store.state.index.role;
		this.role = role;
		if (!token) {
			uni.navigateTo({
				url: '/pages_login/pages/login/login/index'
			});
		} else {
			if(options.type == 'superHK'){ //超级管家
				this.GetSuperAccount()
			}else{
				if (this.role == '') {
					uni.navigateTo({
						url: '/pages/enter/index/index'
					});
				} else {
					this.getAccount();
				}
			}
		}
	},
	onShow() {},
	methods: {
		// 获取账号密码
		getAccount() {
			let userAccount = uni.getStorageSync('userAccount');
			let userPassword = uni.getStorageSync('userPassword');
			if (userAccount && userPassword) {
				this.userAccount = userAccount;
				this.userPassword = userPassword;
			} else {
				service_enter
					.getEnterAccount({})
					.then(res => {
						if (res.code == 1) {
							this.loading = false;
							this.userAccount = res.data.acount;
							this.userPassword = res.data.password;
							this.html = res.data.url;
							uni.setStorageSync('userAccount', res.data.acount);
							uni.setStorageSync('userPassword', res.data.password);
						} else {
							this.$utils.showErr({ title: res.msg });
						}
					})
					.catch(err => {
						this.$utils.showErr();
					});
			}
		},
		
		// 获取超级管家账号
		async GetSuperAccount(){
			let res = await GetSuperAccount()
			if(res.code == 1){
				this.userAccount = res.data.mobile;
				this.userPassword = res.data.password;
				this.html = res.data.url;
			} else {
				this.$utils.showErr({ title: res.msg });
			}
		},

		// 复制内容
		copyContent(content) {
			uni.setClipboardData({ data: String(content) });
		}
	}
};
</script>

<style lang="scss" scoped>
.index {
	width: 100vw;
	height: 100vh;
	background: #fff;
	.navBar {
		position: absolute;
		top: 0;
		left: 0;
	}
	// 背景
	.i_bg {
		height: 442rpx;
		background: #f6f7fb;
	}

	// 内容
	.i_contain {
		margin-top: -64rpx;
		border-radius: 24rpx 24rpx 0px 0px;
		background: #fff;
		overflow: hidden;
		.i_cTit {
			height: 44rpx;
			line-height: 44rpx;
			text-align: center;
			color: #1a1c20;
			font-size: 32rpx;
			margin: 80rpx 0;
		}
		.i_cItem {
			height: 72rpx;
			line-height: 72rpx;
			margin-bottom: 40rpx;
		}
		.i_cLabel {
			width: 206rpx;
			height: 100%;
			color: #666;
			font-size: 24rpx;
			padding-left: 72rpx;
			float: left;
		}
		.i_cCan {
			width: 474rpx;
			height: 100%;
			border-radius: 8rpx;
			background: #f9f6f3;
			overflow: hidden;
		}
		.i_cCopy {
			width: 90rpx;
			height: 100%;
			color: #cbaf87;
			font-size: 24rpx;
			padding-left: 18rpx;
			float: right;
		}
		.i_cCont {
			height: 100%;
			color: #c3ab7c;
			font-size: 32rpx;
			padding: 0 26rpx;
			position: relative;
			overflow: hidden;
			&::after {
				content: '';
				width: 1px;
				height: 22rpx;
				margin-top: -11rpx;
				background: #c6c6c6;
				position: absolute;
				top: 50%;
				right: 0;
			}
		}
	}
	.btn {
		width: 100%;
		margin-top: 50rpx;
		display: flex;
		flex-wrap: wrap;
		padding: 0 100rpx;
		button {
			width: 200rpx;
			margin-bottom: 20rpx;
			font: 500 26rpx/80rpx PingFang SC;
		}
	}
}
</style>
